package com.sg.controllor;


import com.sg.model.Userif;
import com.sg.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/api")
public class MyControllor {
    Logger log = LogManager.getLogger(MyControllor.class);


    @Resource
    private UserService userService ;

    @RequestMapping(value = "/user",method={RequestMethod.GET,RequestMethod.POST})
    public Userif showLoginForm() {
        log.info("开始执行请求...");
        List<Userif> list = null;


      try{
          list = userService.findAll();
          Userif u = new Userif();
          u.setId(Long.valueOf(UUID.randomUUID().toString()));
          u.setUsername("001");
          u.setPassword("23432432432432423423");
          userService.mergeItem(u);

      }catch (Exception e){
          StringWriter sw = new StringWriter();
          e.printStackTrace(new PrintWriter(sw));
          log.info("执行请求出错："+sw);

      }
        log.info("结束执行请求...");
        return list.get(0);
    }




}
